//
//  SDAccountTool.swift
//  Seed
//
//  Created by Samuel on 2017/6/7.
//  Copyright © 2017年 RedSoft. All rights reserved.
//

import Foundation

class SDAccountTool: NSObject {
    //单例
    static let shared = SDAccountTool()
    
    //account存储目录
    private var accountPath = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .allDomainsMask, true).first! as NSString).appendingPathComponent("account.archieve")
    
    func saveAccount(_ account:SDAccount) {
        NSKeyedArchiver.archiveRootObject(account, toFile: accountPath)
    }

    func readAccount() -> SDAccount? {
        if let account = NSKeyedUnarchiver.unarchiveObject(withFile: accountPath) as? SDAccount{
            return account
        }else{
            return nil
        }
    }
    
    func clearAccount() {
         NSKeyedArchiver.archiveRootObject("", toFile: accountPath)
    }
}
